//
//  DKLoginCodeLoginView.m
//  DanKU
//
//  Created by 吴斌 on 2023/9/20.
//

#import "DKLoginCodeLoginView.h"
#import "DKLoginVoiceAlertView.h"
#import "DKRegisterVoiceView.h"
@interface DKLoginCodeLoginView()

@end
@implementation DKLoginCodeLoginView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = UIColor.whiteColor;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    WeakSelf(self)
    //账号
    self.dk_LoginAccountView = [[DKLoginAccountView alloc] init];
    [self addSubview:self.dk_LoginAccountView];
    [self.dk_LoginAccountView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@(DK_IsWidthScale(30)));
        make.right.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    self.dk_LoginAccountView.goCheckAcountBlock = ^(BOOL isPhoneNull) {//输入手机号检测空
        [weakSelf checkIsNext];
    };
//    self.dk_LoginAccountView.goAccountLoginBlock = ^(NSString * _Nonnull loginAccount) {//发送验证码
//
//    };
//    self.dk_LoginAccountView.goAccountResetBlock = ^{//重新选择手机号
//        if(weakSelf.goAccountResetBlock){
//            weakSelf.goAccountResetBlock();
//        }
//    };
    //验证码
    self.dk_LoginMsgCodeView = [[DKLoginMsgCodeView alloc] init];
    [self addSubview:self.dk_LoginMsgCodeView];
    [self.dk_LoginMsgCodeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@(DK_IsWidthScale(30)));
        make.right.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(self.dk_LoginAccountView.mas_bottom).offset(DK_IsWidthScale(20));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    self.dk_LoginMsgCodeView.goCheckMsgCodeBlock = ^(BOOL isPhoneCodeNull) {//输入验证码检测空
        [weakSelf checkIsNext];
    };
    //语音验证码
    DKRegisterVoiceView *dk_LoginVoiceView = [[DKRegisterVoiceView alloc] init];
    [self addSubview:dk_LoginVoiceView];
    [dk_LoginVoiceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(self.dk_LoginMsgCodeView.mas_bottom).offset(DK_IsWidthScale(20));
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
    dk_LoginVoiceView.goRegisterVoiceBlock = ^{//语音验证码
//        if([weakSelf.dk_LoginAccountView isCanSendCode]){
            [weakSelf.dk_LoginAccountView sendVoiceCode];
//        }else{
//            [DKAlertHelper showMessage:@"The verification code sending is busy, please try again later"];
//        }
        
//        [DKLoginVoiceAlertView dk_ShowVoiceAlertViewNextCompleteIsDismiss:YES withVoice:^{
//            [weakSelf.dk_LoginAccountView sendVoiceCode];
//        } WithSms:^{
//            [weakSelf.dk_LoginAccountView sendLoginMsgCode];
//        }];
    };
}
-(void)setSmsType:(NSString *)smsType{
    _smsType = smsType;
    self.dk_LoginAccountView.smsType = _smsType;
}
//检查输入手机号/密码，是否勾选协议
- (void)checkIsNext{
    NSString * account = self.dk_LoginAccountView.dk_LoginAccountTextField.text;
    NSString * code = [self.dk_LoginMsgCodeView getLoginCode];
    if(account.length&&code.length){
        if(self.goCheckLoginCodeBlock){
            self.goCheckLoginCodeBlock(false);
        }
    }else{
        if(self.goCheckLoginCodeBlock){
            self.goCheckLoginCodeBlock(true);
        }
    }
}
- (NSString *)getLoginPhone{
    return self.dk_LoginAccountView.dk_LoginAccountTextField.text;
}
- (NSString *)getLoginCode{
    return [self.dk_LoginMsgCodeView getLoginCode];
}
- (void)clearLogin{
    self.dk_LoginAccountView.dk_LoginAccountTextField.text = @"";
    self.dk_LoginMsgCodeView.dk_LoginMsgCodeTextField.text = @"";
}
@end
